package com.guo.dms.common.shiro.entity;

import java.io.Serializable;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import com.guo.dms.common.menu.entity.Menu;
import com.guo.dms.dept.permission.entity.Permission;
import com.guo.dms.dept.role.entity.Role;
import com.guo.dms.dept.user.entity.User;

public class ShiroUser implements Serializable{
	private static final long serialVersionUID = 1L;
	private User user;
	private List<Role> roles;
	private List<Permission> permissions;
	private List<Menu> menus;
	/*
	 * shiroUser中 user属性是必须的
	 */
	public ShiroUser(User user) {
		super();
		this.user = user;
	}
	
	
	
	public User getUser() {
		return user;
	}
	public void setUser(User user) {
		this.user = user;
	}
	public List<Role> getRoles() {
		return roles;
	}
	public void setRoles(List<Role> roles) {
		this.roles = roles;
	}
	public List<Permission> getPermissions() {
		return permissions;
	}
	public void setPermissions(List<Permission> permissions) {
		this.permissions = permissions;
	}
	public List<Menu> getMenus() {
		return menus;
	}
	public void setMenus(List<Menu> menus) {
		this.menus = menus;
	}
	@Override
	public String toString() {
		return "ShiroUser [user=" + user + ", roles=" + roles + ", permissions=" + permissions + ", menus=" + menus
				+ "]";
	}
	
	
	public static Set<String> getRoleNameSet(List<Role> roles){
		
		Set<String> roleSet=new HashSet<>();
		for (Role role : roles) {
			roleSet.add(role.getCode());
		}
		return roleSet;
	}
	 
	public static Set<String> getPermissionSet(List<Permission> permissions){
		Set<String> roleSet=new HashSet<>();
		for (Permission permission : permissions) {
			roleSet.add(permission.getPermission());
		}
		return roleSet;
	}
	
}
